package apof.util
{
	import flash.filesystem.*;
	import flash.errors.EOFError;
	import mx.utils.StringUtil;
	import flash.utils.Dictionary;
	
	public class ConfigureReader
	{
		private static var eof:Boolean=false;
		private static var map:Object=prototype;
		protected static var fin:FileStream=init();
 		
		
		protected static function init():FileStream{
//			var f:File=new File(File.documentsDirectory.nativePath+"\\Apof\\Apof.configure");
			var f:File=new File(File.applicationResourceDirectory.resolve("Apof.configure").url);
			trace(f.nativePath);

			fin = new FileStream();
			fin.open(f,FileMode.READ);

			while(!eof) {
			var name:String=readWord();
			var value:String=readWord();
			map[name]=value;
			}

			fin.close();
			return fin;
		} 
		
		public static function get cfg() :Object {
			return map;
		}
		
		private static function readWord():String {
			var c:String;
			var s:String="";
			while(true) {
				try {
					c=fin.readMultiByte(1,"gb2312");
				}catch (error:EOFError) {
					eof=true;
					break;
				}
				if(c=="=" || c=="\n") break;
				s+=c;
			}
			return mx.utils.StringUtil.trim(s);
		}
	}
}